package chaowan.Mapper;

import chaowan.pojo.GoodsCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsCategoryMapper {

    @Select("SELECT * FROM goods_category")
    List<GoodsCategory> selectAll();

    @Select("SELECT * FROM goods_category WHERE cid = #{cid}")
    GoodsCategory selectById(Long cid);

    @Insert("INSERT INTO goods_category(title, pid, state) VALUES(#{title}, #{pid}, #{state})")

    @Options(useGeneratedKeys = true, keyProperty = "cid")
    void insert(GoodsCategory category);

    @Update("UPDATE goods_category SET title=#{title}, pid=#{pid}, state=#{state} WHERE cid=#{cid}")
    void update(GoodsCategory category);

    @Delete("DELETE FROM goods_category WHERE cid = #{cid}")
    void deleteById(Long cid);

    @Select("SELECT cid, title, pid, state FROM goods_category WHERE state = 1")
    List<GoodsCategory> findAllActive();
}